using DeZhen.CollaborationPlatform.IService.ApiCallLog;
using DeZhen.CollaborationPlatform.Model.Common;
using DeZhen.CollaborationPlatform.Model.DTO.ApiCallLog;
using DeZhen.CollaborationPlatform.Model.DTO.ApiCallLog;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace DeZhen.CollaborationPlatform.Web.Controllers
{
    /// <summary>
    /// 接口调用日志
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ApiCallLogController : ControllerBase
    {
        private readonly IApiCallLogService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public ApiCallLogController(IApiCallLogService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取接口调用日志分页列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet(Name = "GetApiCallLogPaged")]
        public async Task<PageResult<ApiCallLogDTO>> GetApiCallLogPagedAsync([FromQuery] QueryApiCallLogPage param)
        {
            return await _service.GetListToPageAsync(param);
        }

        /// <summary>
        /// 获取接口调用日志列表
        /// </summary>
        [HttpGet(Name = "GetApiCallLogList")]
        public async Task<List<ApiCallLogDTO>> GetApiCallLogList([FromQuery] QueryApiCallLog param)
        {
            return await _service.GetListAsync(param);
        }

        /// <summary>
        /// 根据ID获取接口调用日志对象DTO
        /// </summary>
        [HttpGet(Name = "GetApiCallLog")]
        public async Task<ApiCallLogDTO> GetApiCallLogAsync([FromQuery, Required] long id)
        {
            return await _service.GetByIdAsync(id);
        }

        /// <summary>
        /// 新增接口调用日志
        /// </summary>
        [HttpPost(Name = "AddApiCallLog")]
        public async Task<long> AddApiCallLogAsync(ApiCallLogAdd input)
        {
            return await _service.AddAsync(input);
        }

        /// <summary>
        /// 更新接口调用日志
        /// </summary>
        [HttpPut(Name = "EditApiCallLog")]
        public async Task<bool> EditApiCallLogAsync(ApiCallLogEdit input)
        {
            return await _service.UpdateAsync(input);
        }

        /// <summary>
        /// 删除接口调用日志
        /// </summary>
        [HttpDelete(Name = "DeleteApiCallLog")]
        public async Task DeleteApiCallLogAsync(long id)
        {
            await _service.DeleteAsync(id);
        }
    }
}